<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="ExportDRG.aspx.cs" Inherits="ExportDRG" Title="ExportDRG" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<%@ Register Namespace="NS_Controls" TagPrefix="cc1" %>
<%@ Register Namespace="CustomControlsNS" TagPrefix="cc2" %>
<asp:Content ID="ContentDefault" ContentPlaceHolderID="ContentPlaceHolderContent"
    runat="Server">
    <link href="../../Styles/themes/fancy/tabs.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/themes/fancy/fancy-blue/fancy-blue.css" rel="stylesheet"
        type="text/css" />
    <asp:UpdatePanel ID="upExportDRG" runat="server">
        <ContentTemplate>
            <div style="padding-bottom: 20px">
                <ajaxToolKit:TabContainer ID="tabContainer" runat="server" CssClass="fancy fancy-blue"
                    AutoPostBack="true" OnActiveTabChanged="tabActive_TabChanged">
                    <ajaxToolKit:TabPanel ID="tabExportDRG" runat="server" HeaderText="Export DRG">
                        <ContentTemplate>
                            <div id="divTitluPagina" runat="server" style="height: 100%; overflow: auto; display: block">
                                <table id="tblTitlu" runat="server" width="98%">
                                    <tr>
                                        <td>
                                            <div class="menu_th">
                                                <table>
                                                    <tr>
                                                        <td>
                                                            <asp:Label ID="lblExpDRG" runat="server" CssClass="menu_th1">Export DRG</asp:Label>
                                                        </td>
                                                        <td>
                                                            <asp:UpdateProgress ID="UpdateProgressExpDRG" runat="server" DisplayAfter="100">
                                                                <ProgressTemplate>
                                                                    <span id="spnProgress" class="clsTextBoldYellow">(<% =Resources.GridView.PageLoading %>)</span>
                                                                </ProgressTemplate>
                                                            </asp:UpdateProgress>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <table width="98%">
                                <tr class="tdn">
                                    <td style="width: 15%" align="right">
                                        <asp:Literal ID="startDate" runat="server" Text="<%$ Resources:DatabaseStrings, StartDate%>" />
                                        :&nbsp;
                                    </td>
                                    <td style="width: 35%">
                                        <span class="tdSmall">
                                            <asp:TextBox ID="txtDataStart" runat="server" MaxLength="10" />
                                            <asp:ImageButton ID="imgDataStart" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png"
                                                BorderWidth="0" Width="16" Height="16" Style="position: relative; top: 0; left: 0;" />
                                            <ajaxToolKit:FilteredTextBoxExtender ID="FilteredTextBoxExtenderStart" runat="server"
                                                TargetControlID="txtDataStart" ValidChars=".-/0123456789" />
                                            <ajaxToolKit:CalendarExtender ID="calDataStart" runat="server" TargetControlID="txtDataStart"
                                                PopupButtonID="imgDataStart" Format="dd/MM/yyyy" />
                                            <ajaxToolKit:CalendarExtender ID="calDataStart2" runat="server" TargetControlID="txtDataStart"
                                                Format="dd/MM/yyyy" />
                                        </span>
                                    </td>
                                    <td style="width: 15%" align="right">
                                        <asp:Literal ID="endDate" runat="server" Text="<%$ Resources:DatabaseStrings, EndDate%>" />
                                        :&nbsp;
                                    </td>
                                    <td style="width: 35%">
                                        <span class="tdSmall">
                                            <asp:TextBox ID="txtDataEnd" runat="server" MaxLength="10" />
                                            <asp:ImageButton ID="imgDataEnd" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png"
                                                BorderWidth="0" Width="16" Height="16" Style="position: relative; top: 0; left: 0;" />
                                            <ajaxToolKit:FilteredTextBoxExtender ID="FilteredTextBoxExtenderEnd" runat="server"
                                                TargetControlID="txtDataEnd" ValidChars=".-/0123456789" />
                                            <ajaxToolKit:CalendarExtender ID="calDataEnd" runat="server" TargetControlID="txtDataEnd"
                                                PopupButtonID="imgDataEnd" Format="dd/MM/yyyy" />
                                            <ajaxToolKit:CalendarExtender ID="calDataEnd2" runat="server" TargetControlID="txtDataEnd"
                                                Format="dd/MM/yyyy" />
                                        </span>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 15%" class="tdn" align="right">
                                        Tip Export:
                                    </td>
                                    <td style="width: 15%" class="tdn">
                                        <span class="tdSmall">
                                            <asp:DropDownList ID="drpExportType" runat="server" Width="350px" />
                                        </span>
                                    </td>
                                    <td style="width: 15%" class="tdn" align="right">
                                        Status Export:
                                    </td>
                                    <td style="width: 15%" class="tdn">
                                        <span class="tdSmall">
                                            <asp:DropDownList ID="drpExportStatus" runat="server" Width="350px" />
                                        </span>
                                    </td>
                                </tr>
                                <tr class="tdn">
                                    <td colspan="4">
                                        <cc2:CustomButton ID="btnSave" runat="server" Text="Importa MDB" OnServerClick="btnSave_Click"
                                            OnClick="StartTheTimer();" />
                                        <cc2:CustomButton ID="btnClear" runat="server" Text="Goleste MDB" OnServerClick="btnClear_Click" />
                                        <cc2:CustomButton ID="btnDownload" runat="server" Text="Descarca MDB" OnServerClick="btnDownload_Click" />
                                        <!--
                                        <cc2:CustomButton ID="btnThread" runat="server" Text="Thread"
                                            OnServerClick="btnThread_Click" OnClick="StartThreadTimer();" />
                                        <cc2:CustomButton ID="btnCheckStatus" runat="server" Text="Thread Status"
                                            OnServerClick="btnThreadStatus_Click" />
                                        -->
                                    </td>
                                </tr>
                            </table>
                            <div id="divMessageBox" class="greenFont" style="border: 5px; border-color: Red;
                                height: 50px; width: 98%; background-color: #C2DFFF;">
                                <asp:Literal ID="mesajStatus" runat="server" />
                                <span id="spanTimer" style="height: 50px"></span>
                                <!--
								<span id="spanTimer" style="height:50px; background-color: yellow"></span>
								<span id="spanMessage" style="height:50px; background-color: Aqua"></span>
					            <span id="stopTimer" style="visibility:hidden"><a onclick="StopTheTimer()">Stop</a></span>
					            <asp:UpdatePanel ID="upStatus" runat="server">
									<ContentTemplate>
										<span id="span3" style="height:50px; background-color: Fuchsia">
												<asp:Literal ID="mesajStatusAjax" runat="server" />
										</span>
									</ContentTemplate>
					            </asp:UpdatePanel>
					            <span id="spanPageMethod" style=""></span>
	                            -->
                            </div>
                            <asp:Literal ID="output" runat="server" />
                        </ContentTemplate>
                    </ajaxToolKit:TabPanel>
                    <ajaxToolKit:TabPanel ID="tbVisualImport" runat="server" HeaderText="Vizualizare Import DRG">
                        <ContentTemplate>
                            <div id="divNOMSIUI" runat="server" style="height: 100%; overflow: auto; display: block;">
                                <table width="98%">
                                    <tr>
                                        <td>
                                            <div class="menu_th">
                                                <table>
                                                    <tr>
                                                        <td>
                                                            <asp:Label ID="lblNomSIUI" runat="server" CssClass="menu_th1">Vizualizare DRG</asp:Label>
                                                        </td>
                                                        <td>
                                                            <asp:UpdateProgress ID="UpdateProgressNOMSIUI" runat="server" DisplayAfter="100">
                                                                <ProgressTemplate>
                                                                    <span id="spnProgress" class="clsTextBoldYellow">(<% =Resources.GridView.PageLoading %>)</span>
                                                                </ProgressTemplate>
                                                            </asp:UpdateProgress>
                                                        </td>
                                                    </tr>
                                                </table>
                                                <table width="100%">
                                                    <tr>
                                                        <td style="width: 20%" class="tdn">
                                                            Selectati tabelul:
                                                        </td>
                                                        <td id="tdUpload" runat="server" class="tdn" colspan="4">
                                                            <asp:DropDownList ID="drpNomenclator" runat="server" Width="350px" AutoPostBack="true"
                                                                OnSelectedIndexChanged="ddlNom_SelectedIndexChanged" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 20%" class="tdn">
                                                            Tip Export:
                                                        </td>
                                                        <td class="tdn" colspan="4">
                                                            <span class="tdSmall">
                                                                <asp:DropDownList ID="drpTypeExport" runat="server" Width="350px" AutoPostBack="true"
                                                                    OnSelectedIndexChanged="LoadCombo" />
                                                            </span>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <table width="98%">
                                <tr>
                                    <td>
                                        <cc1:ExtendedGridView runat="server" ID="grDRG" UseDefaultStyle="true" ShowEditLink="false"
                                            ShowInsertLink="false" AutoSave="true" AllowSorting="true" AllowPaging="true"
                                            EnableEdit="false" showDeleteButton="true" showEditButton="false" PageSize="15"
                                            AutoGenerateColumns="true" EnableFilter="true" EnablePageSize="true" EnableExport="false"
                                            AutoGenerateEditButton="false" Width="98%">
                                        </cc1:ExtendedGridView>
                                        <div class="divEndTotal">
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </ContentTemplate>
                    </ajaxToolKit:TabPanel>
                    <ajaxToolKit:TabPanel ID="tbVerifyExport" runat="server" HeaderText="Verificare Export Hipocrate">
                        <ContentTemplate>
                            <div id="div1" runat="server" style="height: 100%; overflow: auto; display: block;">
                                <table width="98%">
                                    <tr>
                                        <td>
                                            <div class="menu_th">
                                                <table>
                                                    <tr>
                                                        <td>
                                                            <asp:Label ID="Label1" runat="server" CssClass="menu_th1">Verificare Export Hipocrate</asp:Label>
                                                        </td>
                                                        <td>
                                                            <asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="100">
                                                                <ProgressTemplate>
                                                                    <span id="spnProgress" class="clsTextBoldYellow">(<% =Resources.GridView.PageLoading %>)</span>
                                                                </ProgressTemplate>
                                                            </asp:UpdateProgress>
                                                        </td>
                                                    </tr>
                                                </table>
                                                <table width="100%">
                                                    <tr>
                                                        <td style="width: 20%" class="tdn">
                                                            Selectati tabelul:
                                                        </td>
                                                        <td class="tdn" colspan="4">
                                                            <asp:DropDownList ID="drpExportVerify" runat="server" Width="350px" AutoPostBack="true"
                                                                OnSelectedIndexChanged="ddlNomVerify_SelectedIndexChanged" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 20%" class="tdn">
                                                            Tip Export:
                                                        </td>
                                                        <td class="tdn" colspan="4">
                                                            <span class="tdSmall">
                                                                <asp:DropDownList ID="drpTypeExportVerify" runat="server" Width="350px" AutoPostBack="true"
                                                                    OnSelectedIndexChanged="LoadComboVerify" />
                                                            </span>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <table width="98%">
                                <tr>
                                    <td>
                                        <cc1:ExtendedGridView runat="server" ID="grExportVerify" UseDefaultStyle="true" ShowEditLink="false"
                                            ShowInsertLink="false" AutoSave="true" AllowSorting="true" AllowPaging="true"
                                            EnableEdit="false" showDeleteButton="true" showEditButton="false" PageSize="15"
                                            AutoGenerateColumns="true" EnableFilter="true" EnablePageSize="true" EnableExport="false"
                                            AutoGenerateEditButton="false" Width="98%">
                                        </cc1:ExtendedGridView>
                                        <div class="divEndTotal">
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </ContentTemplate>
                    </ajaxToolKit:TabPanel>
                </ajaxToolKit:TabContainer>
                <div id="divLinkHome" style="padding: 10px">
                    <asp:Image runat="Server" ID="imgReturnMain" ImageUrl="~/Images/Hipocrate/icon_home.gif"
                        AlternateText="Click to return" UseSubmitBehavior="false" Style="cursor: pointer" />
                    <asp:HyperLink ID="lnkMainPage" runat="server" Text="Inapoi la pagina principala"
                        NavigateUrl="~/Default.aspx" />
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
    <script language="javascript" type="text/javascript">
        var g_str_div = 'spanPageMethod';
        var g_str_spanTrace = 'spanTrace';

        var delayTimer = 1000;
        var timer = null;
        var timeStr = null;

        function hideModal() {
            StopTheTimer();
            if (timeStr != null)
                $get('spanTimer').innerHTML = '<br/><img src="../../Images/Hipocrate/check.gif" />' +
					'Exportul s-a realizat in:   ' + timeStr;
            else
                $get('spanTimer').innerHTML = '<br/><img src="../../Images/Hipocrate/del.gif" />' +
					'Exportul nu s-a realizat!';
        }

        var startUpTime;
        function StartTheTimer() {
            startUpTime = new Date();
            timer = window.setInterval("getTime()", delayTimer);
        }

        function StartThreadTimer() {
            $get(g_str_div).innerHTML = '[start]';
            startUpTime = new Date();
            timer = window.setInterval("getTime()", delayTimer);
            $get('stopTimer').style.visibility = 'visible';
        }

        function StopTheTimer() {
            clearTimeout(timer);
            if ($get('stopTimer') != null)
                $get('stopTimer').style.visibility = 'hidden';
        }

        function getTime() {
            var time = new Date();
            var diff = ((24 + time.getHours() - startUpTime.getHours()) % 24) * 3600 + time.getMinutes() * 60 + time.getSeconds() - startUpTime.getMinutes() * 60 - startUpTime.getSeconds();
            var curr_sec = diff % 60;
            var curr_min = (diff - curr_sec) / 60;
            timeStr = curr_min + " : " + (curr_sec < 10 ? '0' : '') + curr_sec + ' ';
            $get('spanTimer').innerHTML = "<br />&nbsp;&nbsp;&nbsp;" + timeStr;
            if ($get('spanMessage') == null) return;
            var existingText = $get('spanMessage').innerHTML;
            if (existingText == '')
                existingText = '...';
            //$get('spanMessage').innerHTML = '(' + existingText + ')';
            $get('spanMessage').innerHTML = existingText + '*';
            //messageStatus('');
        }

        var stillWaiting = false;
        function messageStatus(message) {
            if (stillWaiting) {
                $get(g_str_div).innerHTML += " [...] ";
                return;
            }
            stillWaiting = true;
            PageMethods.getStatus(onGetdataSuccess, onGetdataFail);
            $get(g_str_div).innerHTML += " [*] Fetching status...";
            xmlhttp = new XMLHttpRequest();
            xmlhttp.open("GET", "ExportDRG.aspx?getStatus=myId", true);
            xmlhttp.onreadystatechange = function () {
                $get(g_str_div).innerHTML += ' [' + xmlhttp.readyState + '] ' + xmlhttp.status;
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    $get(g_str_div).innerHTML += ' -- ' + xmlhttp.responseText;
                    stillWaiting = false;
                }
            }
            xmlhttp.send();
        }

        function onGetdataSuccess(response) {
            $get('spanMessage').innerHTML = response;
            var div = $get(g_str_div);
            div.innerHTML += response + "<br/>";
            div.scrollTop = 99999;
        }
        function onGetdataFail() {
            $get('spanMessage').innerHTML = '-';
        }

        function testPage(x) {
            $get(g_str_div).innerHTML += '<br/>' + x;
        }
    </script>
</asp:Content>
